package org.zjx.analysis.analyze.association;

import lombok.Getter;
import org.zjx.analysis.analyze.window.AbstractWindowAnalyzer;
import org.zjx.analysis.identify.IdentifyTessUtil;
import org.zjx.command.util.ImageUtil;
import org.zjx.window.window.IWindow;

import java.awt.*;
import java.awt.image.BufferedImage;

public class AssociationHomeAnalysis extends AbstractWindowAnalyzer {
    @Getter
    private int chamberNumber; //输入的店铺编号

    public AssociationHomeAnalysis(IWindow window) {
        super("商会主界面", "商会", window);
    }

    public Rectangle getJumpRectangle(){
        return conversion(windowArea,areaMap.get("跳转").getRectangle());
    }

    @Override
    protected void initResources() {
        areaMap.put("跳转店铺号", new ResolutionArea(ImageUtil.createRect(80,64,210,77)));
        areaMap.put("跳转", new ResolutionArea(ImageUtil.createRect(223,62,278,79)));
        areaMap.put("离开", new ResolutionArea(ImageUtil.createRect(240,408,278,425)));
    }

    @Override
    public Rectangle closeArea() {
        return ImageUtil.createRect(277,5,286,14);
    }

    @Override
    public Rectangle getOriginBounds() {
        return ImageUtil.createRect(179,24,471,463);
    }

    @Override
    public Rectangle getRefImageArea() {
        return ImageUtil.createRect(13,64,68,77);
    }

    @Override
    public BufferedImage getRefImage() {
        return ImageUtil.createImage("iVBORw0KGgoAAAANSUhEUgAAADgAAAAOCAYAAAB6pd+uAAAFDUlEQVR42pVW+1OWRRTmT2impiyMQolEDAUkIBDCQUIgEAERUSyUEAZDGRKUEEFEBVFRFMpLaKQJYWokpnhBbioCcpGhRkoRoSy6iAP9AHPa5zC7ve/3fQz1zJx5d89e3t3z7HN2zZ6Z8irBrGwdKSJqNcm6tP0HPzXy/RfbuDmLbB1cTbbhXwuDwtjmOHsoP+q+gaEUGLqMvP0WTTh3THyikW+6rQMlrN9g5DebMseFYBm7CgiQddjsBQHsM3d00/mldXR/T6fOfUsWTvPIY3EEbd9frAyob2pW9eyCA2Tt7s3jDOEvAgv/5boGqr3ZRI3NrXTh6nWT//SJWMlj5FzSio6fMFo/zEzuND0rhzugbGkzh54MDakFjI2N0ejoK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aL7FolMfNV2VfLZAtcZcByIjog9cMToWly9vU9cM95ZemzaIw9Gvt7FJzVtc2GL9kPs7cxo03hMiBnfkFOqa8fAPVBK7iOETHJnC5RFyoeD8ODv4+aXIqOnSUdT0iFpcvnm6IctTquPELWpwE+S9DTW3YlKFbS+nJMr5DDU8T3rISsxzf0jNo5+1P0UmpFPpBgi5zGdrSuETWC3QGBg3bZ3j48HhDA7Om5kP/SCEDQz/emp4hy4zenHKtOB0TrRFaleV/APCwvbRZl3ClAAAAAElFTkSuQmCC");
    }

    @Override
    public void analyze(BufferedImage image) {
        Rectangle rectangle = conversion(windowArea,areaMap.get("跳转店铺号").getRectangle());
        BufferedImage bufferedImage = ImageUtil.cutImage(screenshot,rectangle);
        String numberStr = IdentifyTessUtil.tessIdentify(bufferedImage);
        chamberNumber = numberStr.isEmpty()?0:Integer.parseInt(numberStr);
    }
}
